package com.tj.jinzao.base;

import android.app.Activity;
import android.app.Application;

import java.util.LinkedList;

/**
 * 除主界面外所有Activity销毁
 * 
 * */
public class AppExit extends Application {
	private LinkedList<Activity> activitAll = null;
	private static AppExit instance;

	private AppExit() {
		activitAll = new LinkedList<Activity>();
	}

	/**
	 * 单例模式中获取唯一的MyApplication实例
	 * 
	 * @return
	 */
	public static AppExit getInstance() {
		if (null == instance) {
			instance = new AppExit();
		}
		return instance;

	}

	// 添加Activity到容器中
	public void addActivity(Activity activity) {
		if (activitAll != null && activitAll.size() > 0) {
			if (!activitAll.contains(activity)) {
				activitAll.add(activity);
			}
		}
		else if(activitAll != null){
			activitAll.add(activity);
		}

	}

	// 遍历所有Activity并finish
	public void exit() {
		if (activitAll != null && activitAll.size() > 0) {
			for (Activity activity : activitAll) {
				activity.finish();
			}
		}
//		System.exit(0);
	}

}
